
package cz.czu.pef.DataModelling.entityObjects;

import java.util.*;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * This entity represents kind of medical examination.
 * 
 * @author rstribrn
 *
 */
@Entity
@Table(name = "MEDICAL_EXAMINATION_TYPE")
@NamedQueries({
	@NamedQuery(name="findMedicalExaminationTypeByCode", query="SELECT met FROM MedicalExaminationTypeEntityImpl met WHERE met.code = :code")
})
public class MedicalExaminationTypeEntityImpl extends CommonPersistenceEntityObjectImpl implements IdPersistenceEntityObject
{
	private static final long serialVersionUID = -4318181001409286326L;

	/*
	 * Entity attributes (some inherited).
	 */

	/*
	 * Relations
	 */
	@OneToMany(fetch=FetchType.EAGER, targetEntity=MedicalExaminationTypeForRoleTypeEntityImpl.class, mappedBy="medicalExaminationType", cascade={CascadeType.REMOVE})
	private Set<MedicalExaminationTypeForRoleTypeEntityImpl> medicalExaminationTypeForRoleTypes;

	@OneToMany(fetch=FetchType.EAGER, targetEntity=MedicalExaminationEntityImpl.class, mappedBy="medicalExaminationType", cascade={CascadeType.REMOVE})
	private Set<MedicalExaminationEntityImpl> medicalExaminations;

	public MedicalExaminationTypeEntityImpl()
	{
		super(null, null, null);
	}

	public MedicalExaminationTypeEntityImpl(String medicalExaminationTypeCode, String medicalExaminationTypeName, String medicalExaminationTypeDescription)
	{
		super(medicalExaminationTypeCode, medicalExaminationTypeName, medicalExaminationTypeDescription);
	}

	public Set<MedicalExaminationEntityImpl> getMedicalExaminations()
	{
		return medicalExaminations;
	}

	public List<MedicalExaminationEntityImpl> getMedicalExaminationsAsList()
	{
		return new ArrayList<MedicalExaminationEntityImpl>(getMedicalExaminations());
	}

    
  public void setMedicalExaminationTypeForRoleTypes(Set<MedicalExaminationTypeForRoleTypeEntityImpl> medicalExaminationTypeForRoleTypes)
  {
    this.medicalExaminationTypeForRoleTypes = medicalExaminationTypeForRoleTypes;
  }

  
  public void setMedicalExaminations(Set<MedicalExaminationEntityImpl> medicalExaminations)
  {
    this.medicalExaminations = medicalExaminations;
  }

    @Override
	public String toString()
	{
		StringBuilder builder = new StringBuilder();
		builder.append("MedicalExaminationTypeEntityImpl [toString()=");
		builder.append(super.toString());
		builder.append("]");
		return builder.toString();
	}

	public Set<MedicalExaminationTypeForRoleTypeEntityImpl> getMedicalExaminationTypeForRoleTypes()
	{
		return medicalExaminationTypeForRoleTypes;
	}

	public List<MedicalExaminationTypeForRoleTypeEntityImpl> getMedicalExaminationTypeForRoleTypesAsList()
	{
		return new ArrayList<MedicalExaminationTypeForRoleTypeEntityImpl>(getMedicalExaminationTypeForRoleTypes());
	}
	
	/* (non-Javadoc)
	 * @see cz.czu.pef.DataModelling.domainObjects.MedicalExaminationType#canBeRemoved()
	 */
	@Override
	public boolean canBeRemoved()
	{
		return getMedicalExaminationTypeForRoleTypes().size() == 0 && getMedicalExaminations().size() == 0;
	}
}